package com.gopay.test.dao.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.gopay.test.dao.UserInfoQueryDAO;
import com.gopay.test.entity.UserInfo;

/**
 * UserInfoQuery DAO实现
 * 
 * @CustCorpInfoQueryManager.java
 * @author liuxin
 * @2013-1-5 上午9:49:38 www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("userInfoQueryDao")
public class UserInfoQueryDAOImpl extends BaseDAOImpl<UserInfo, Serializable> implements UserInfoQueryDAO {

    @Override
    public UserInfo getUserInfoByEmail(String email) {
        String hql = "from UserInfo where email = :email and userStat <> :userStat1 and userStat <> :userStat2";

        Map<String, Object> param = new HashMap<String, Object>();
        param.put("email", email);
        List<UserInfo> userInfoList = this.findByHql(hql, param);
        if (userInfoList == null || userInfoList.size() == 0) {
            return null;
        }
        return userInfoList.get(0);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<UserInfo> getByCustId(String custId) {
        return getHibernateTemplate().find(" from UserInfo t where t.custId = '" + custId + "'");
    }

    /* (non-Javadoc)
     * @see com.gopay.common.user.dao.UserInfoQueryDAO#getUserInfoByEmailAndOprId(java.lang.String, java.lang.String, java.lang.String)
     */
    @Override
    public UserInfo getUserInfoByEmailAndOprId(String email, String oprId) {
        // TODO Auto-generated method stub
        DetachedCriteria criteria = DetachedCriteria.forClass(UserInfo.class);
        criteria.add(Restrictions.eq("email",email));
        if(StringUtils.isNotBlank(oprId)){
            criteria.add(Restrictions.eq("operId",oprId));
        }
        List<UserInfo> list = this.findByCriteria(criteria);
        return list.size() > 0 ? list.get(0) : null;
    }

    public List<UserInfo> getPasswordLockedStatusUser() {
    	DetachedCriteria criteria = DetachedCriteria.forClass(UserInfo.class);
    	
    	List<UserInfo> list = this.findByCriteria(criteria);
    	return list;
    }
}
